const _ = require('lodash');

// const { YHForms_step_components } = require('../constants/mockData');

const objectToString = (obj) => {
  const { language } = global.config;
  const isTS = language === 'typescript';
  if (typeof obj === 'function') {
    return obj.toString();
  }
  const ret = _.cloneDeep(obj);

  // const s1 = JSON.stringify(ret, (k, v) => {
  //   if (typeof v === 'function') {
  //     const s = v.toString();
  //     const cur_s =
  //       global.config.storeType === 'redux' ? s.replace(/store./g, '') : s;
  //     return `【FUNC】${cur_s}【END】`;
  //   }
  //   // if(){}
  //   return v;
  // });

  const s1 = JSON.stringify(ret, (k, v) => {
    if (typeof v === 'function') {
      if (typeof v === 'function' && k === 'render') {
        const com = v();
        return isTS
          ? `【FUNC】(v:any,row:any)=>${com}【END】`
          : `【FUNC】(v,row)=>${com}【END】`;
      }
      const s = v.toString();
      const cur_s =
        global.config.storeType === 'redux' ? s.replace(/store./g, '') : s;
      return `【FUNC】${cur_s}【END】`;
    }

    return v;
  });

  // console.log('s1', s1);
  const s2 = s1
    .replace(/\\n /g, '')
    .replace(/\"【FUNC】/g, '')
    .replace(/【END】\"/g, '');
  return s2;
};

module.exports = objectToString;
